﻿using System;
using System.Collections.Generic;

namespace HeroDream
{
    class TaskRoom
    {
        public Dictionary<int,Task> tasks;

        public TaskRoom()
        {
            tasks = new Dictionary<int, Task>();
        }


        public void CreateTask()
        {
            int send = 0;
         
            //需要生成几个杀怪任务
            int sum = 0;
            foreach(var v in tasks.Values)
            {
                if (v.Type == TaskType.Battle)
                {
                    sum++;
                }
            }

            for(int i = 0; i < 3 - sum; i++)
            {
                //通过使用派生类构造基类，实现运行时任务为不同的形态（战斗任务和护送任务），来实现类的多态
                Task task = new BattleTask(send++);
                tasks.Add(task.Id, task);
            }

            sum = 0;
            foreach (var v in tasks.Values)
            {
                if (v.Type == TaskType.Convoy)
                {
                    sum++;
                }
            }

            for (int i = 0; i <5 - sum; i++)
            {
                //通过使用派生类构造基类，实现运行时任务为不同的形态（战斗任务和护送任务），来实现类的多态
                Task task = new ConvoyTask(send++);
                tasks.Add(task.Id, task);
            }
        }
        

        public Task GetTask(int key)
        {
            if (!tasks.ContainsKey( key ))
            {
                Console.WriteLine("输入错误");
                return null;
            }
            Task task = tasks[key];
            tasks.Remove(key);
            return task;
        }


        public void OutPut()
        {
            Console.WriteLine("---------任务栏---------");
            foreach(Task task in tasks.Values)
            {
                task.OutPut();
            }
        }


    }
}
